﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Un4seen.Bass;
using Un4seen.Bass.Misc;

using Vwlab;

namespace Vwlab
{
    public class uBass
    {
        internal int stream;
        Error err = new Error();

        public void Init()
        {
            BassNet.Registration("vwlab.ru@gmail.com", "2X1732818152222");
            Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
        }

        public void Close()
        {
            Bass.BASS_Free();
        }

        public void Play(string url)
        {
            if (Bass.BASS_ChannelIsActive(stream) == BASSActive.BASS_ACTIVE_STOPPED)
            {
                Bass.BASS_StreamFree(stream);
            }
            else if (Bass.BASS_ChannelIsActive(stream) == BASSActive.BASS_ACTIVE_PLAYING || Bass.BASS_ChannelIsActive(stream) == BASSActive.BASS_ACTIVE_PAUSED)
            {
                Bass.BASS_ChannelStop(stream);
                Bass.BASS_StreamFree(stream);
            }

            stream = Bass.BASS_StreamCreateURL(url, 0, BASSFlag.BASS_DEFAULT, null, IntPtr.Zero);

            if (stream != 0)
            {
                if (!Bass.BASS_ChannelPlay(stream, true))
                {
                    err.setError(String.Format("{0}", Bass.BASS_ErrorGetCode()));
                }
            }
        }
    }
}
